<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Admin\Controller;
use App\Models\Device;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class DeviceController extends Controller
{
    //
    //添加编辑 广告
    public function addEditDevice(Request $request){
        $id = $request->id;
        if($id){
            $res = Device::where('id',$id)->update($request->all());
        }else{

            if(!$request->device_id)
                return $this->failed('设备编号必传');
            $res = Device::create($request->all());
        }

        if($res){
            return $this->success('操作成功');
        }
        return $this->failed('操作失败');
    }


    //删除广告
    public function deleteDevice(Request $request){
        $id = $request->id;
        $res = Device::where('id',$id)->delete();
        if($res)
            return $this->success('操作成功');

        return $this->failed('操作失败');

    }


    //广告列表
    public function DeviceList(Request $request){

        $list = Device::select(['id','name','device_id'])->get();

        return $this->success($list);
    }



}
